package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理api")
public class WmChannelController {

    @Autowired
    private IWmChannelService iWmChannelService;

    @PostMapping("/list")
    @ApiOperation(value = "根据名字模糊查询频道列表",notes = "author:俊萌")
    @ApiImplicitParam(name = "com.heima.search.dto",value = "查询对象",required = true,dataType = "ChannelDto")
    public ResponseResult listByName(@RequestBody ChannelDto dto){

        return iWmChannelService.listByName(dto);
    }

    @PostMapping
    @ApiOperation(value ="添加频道",notes = "后台添加频道")
    @ApiImplicitParam(name = "com.heima.search.entity",value = "增加对象",required = true,dataType = "WmChannel")
    public ResponseResult saveChannel(@RequestBody WmChannel entity){
        return iWmChannelService.saveChannel(entity);
    }

    @GetMapping("/channels")
    public ResponseResult channels() {
        List<WmChannel> list = iWmChannelService.list();
        return ResponseResult.okResult(list);
    }

    @PutMapping
    public ResponseResult updateChannel(@RequestBody WmChannel entity){
        return iWmChannelService.updateChannel(entity);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteChannel(@PathVariable("id") Integer id){
        return iWmChannelService.deleteChannel(id);
    }
}
